package com.xxrl.shop.domain;

import com.xxrl.shop.common.entity.ItemSimilarity;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
import org.springframework.data.mongodb.core.mapping.MongoId;

import java.io.Serializable;
import java.util.List;

/**
 * @author mis
 */
@Data
@NoArgsConstructor
@Document(value = "product_similar")
public class ProductSimilar implements Serializable {
    @MongoId
    private String id;

    @Field
    private Integer productId;

    @Field
    private String similarIds;

    public ProductSimilar(List<ItemSimilarity> isList, int productId) {
        this.productId = productId;
        StringBuilder sb = new StringBuilder();
        for (ItemSimilarity is : isList) {
            sb.append(',');
            sb.append(is.getProductId2());
        }
        similarIds = sb.substring(1);
    }
}
